<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/taglib.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>应税设置</title>
		<%@ include file="/WEB-INF/jsp/include.jsp"%>
		<script type="text/javascript">
		var isQueryed = false;
		var sbcs_id = "${sbcs_id}";
		
		$(function(){
			setAjaxLoading();
			
			initGrid();
			
			btnQuery();
		});
		
		function initGrid() {
			$('#tt').datagrid({
				fit:true,
				nowrap:true,
				striped: true,
				singleSelect:true,
				pagination:true,
				rownumbers:true,
				idField: "id",
				toolbar:'#tb',
				fitColumns:false,
				columns:[[
					{title:'',field:'ck',checkbox:true,sortable:false,width:'150',align:'left'},				          
					{title:'数据源',field:'ztMc',width:'120',align:'left',halign:'center',sortable:false,resizable: true},
					{title:'年度',field:'ssnd',width:'80',align:'center',halign:'center',sortable:false,resizable: true},
					{title:'会计科目',field:'kmQc',width:'250',align:'left',halign:'center',sortable:false,resizable: true},
					{title:'科目代码',field:'kmDm',width:'120',align:'left',halign:'center',sortable:false,resizable: true},
					{title:'核算项目',field:'hsxmMc',width:'200',align:'left',halign:'center',sortable:false,resizable: true},
					{title:'应税项目',field:'ysxmMc',width:'200',align:'left',halign:'center',sortable:false,resizable: true},
					{title:'应税判别',field:'yspbMc',width:'200',align:'left',halign:'center',sortable:false,resizable: true},
					{title:'计税方法',field:'jsfsMc',width:'200',align:'left',halign:'center',sortable:false,resizable: true},
					{title:'税率',field:'sl',width:'80',align:'right',halign:'center',sortable:false,resizable: true,formatter: function(value, rowData, rowIndex){
						var str = "";
						if (typeof(value) != "undefined" && value != null) {
							if (value != 0 && value != 0.00) {
								str = (value * 100).toFixed(2);
							}	
						}
						
						if (str != "") {
							str = str + "%";
						}
						return str;
					}}
				]],
                pageList : [ 25, 50, 100 ],
				onSortColumn: function (sort, order) {
	        		
				},					
				onLoadSuccess:function(){
					$("#tt").datagrid("clearSelections");
					$("#tt").datagrid("fixRownumber");
					displayMsg($("#tt"));
				}
			});
			
			$('#tt').datagrid("loadData", []);
			
		    var options = $("#tt").datagrid("options");
			var pager = $("#tt").datagrid("getPager");
    		var pagerOptions = pager.pagination("options");
    		pagerOptions.onSelectPage = function (pageNumber, pageSize) {
        		if (!isQueryed) {
					return;
        		}
        		var options = $("#tt").datagrid("options");
        		getGridData(pageNumber, pageSize, options.queryParams);
    		};
    		
    		isQueryed=false;
		}
		
		//获取表格数据
		function getGridData(pageNumber, pageSize, queryParams) {
			var url = '${path}/jcxx/sbcs/yssz/zzs/queryByPage';
			
    		var param = new Object();
		    if (queryParams != null) {
		        for (var p in queryParams) {
		            if (typeof (queryParams[p]) != "function") {
		                param[p] = queryParams[p];
		            }
		        }
		        var gridOptions = $("#tt").datagrid("options");
		        gridOptions.queryParams = queryParams;
		    }
    		param.pageNo = pageNumber;
    		param.pageSize = pageSize;
    		    		
			$.ajax({
        		type:"POST",
       			url:url,
        		data:param,
        		async:true,
       			dataType:"json",
       			success:function(data){
					if(data.code != '0000') {
	     				alert('获取数据时发生错误：' + data.msg);
	     			} else {
        				var pager = $("#tt").datagrid("getPager");
    	    			var pager_param = {
        						total: 1,
        						pageNumber: 1
        				};
        	    		if (data.returnObject.totalRows > 0) {
        	    			pager_param = {
            						total: data.returnObject.totalRows,
            						pageNumber: data.returnObject.currentPageNo
            				};
        	    		}
        	    		pager.pagination(pager_param);
        	    		
        			    var options = $("#tt").datagrid("options");
        			    options.pageNumber = pager_param.pageNumber;
        			    
	     				var gridData = new Object();
	     				gridData.total = data.returnObject.totalRows;
	     				gridData.rows = data.returnObject.rows;	     
	     				$("#tt").datagrid("loadData", gridData);
	     				
	     				isQueryed = true;
	    			}       				
       			},
				error: function() {
					alert('获取数据时发生错误！');
				}       			
       		});
		}
		
		//查询
		function btnQuery(){
			var param = new Object();
			param.sbcs_id = sbcs_id;
			
		    var options = $("#tt").datagrid("options");
		    getGridData(1, options.pageSize, param); 
		}
		
		//增加
		function btnAdd() {
			parent.open_yssz_zzs_add(sbcs_id);
		}
		
		//修改
		function btnEdit() {
			var rows = $('#tt').datagrid('getSelections');
		    if (rows.length == 0) {
		        //$.messager.alert("友情提醒", "请先选择一个项目！", "info");
		        $.alert("pick", "info", "");
		        return;
		    }
		    var row = rows[0];
		    parent.open_yssz_zzs_edit(row.id, sbcs_id);
       	}

		//删除
		function btnDel(){
			var rows = $('#tt').datagrid('getSelections');
		    if (rows.length == 0) {
		        //$.messager.alert("友情提醒", "请先选择一个项目！", "info");
		        $.alert("pick", "info", "");
		        return;
		    }	
			var rowData = rows[0];
			var param = new Object();
			param.id = rowData.id;
			//$.messager.confirm("友情提醒", "删除后将不可恢复，是否删除？", function (b) {
			$.messager.confirm("问题", "请确认是否要删除？", function (b) {
	            if (b) {
	    			$.ajax({
		        		type:"POST",
		       			url:'${path}/jcxx/sbcs/yssz/zzs/delete',
		        		data:param,
		       			dataType:"json",
		       			async: false,
		       			success:function callback(data){
		       				var analyMsg = data;
		       				if(analyMsg.code!="0000"){
		         				//$.messager.alert('友情提醒',analyMsg.msg,'info',function(){});
		       					$.alert("delete", "error", "");
		         			}else{
		         				btnQuery();
		        			}
		       			}
		       		});	
	            }
	        });						
       	}
		
		//查看
		function btnView() {
			var rows = $('#tt').datagrid('getSelections');
		    if (rows.length == 0) {
		        //$.messager.alert("友情提醒", "请先选择一个项目！", "info");
		        $.alert("pick", "info", "");
		        return;
		    }
		    var row = rows[0];
		    parent.open_yssz_zzs_view(row.id, sbcs_id);
       	}
		</script>
	</head>
  <body  style="margin:0px; padding:0px;" > 
	<%@ include file="/WEB-INF/jsp/loading.jsp" %>
	<div class="easyui-layout" fit="true" >
		<div data-options="region:'center',title:'',split:false,border: true">
			<table id="tt" data-options="border:false,title:''"></table>
		</div>
	</div>
    <div id="tb" style="padding: 1px; height: auto; display: none;">
        <div>
        	<a id="btn_add_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" plain="false" onclick="btnAdd()">新增</a>
			<a id="btn_edit_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-edit" plain="false" onclick="btnEdit()">修改</a>
			<a id="btn_del_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-remove" plain="false" onclick="btnDel()">删除</a>
			<a id="btn_view_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-search" plain="false" onclick="btnView()">查看</a>
        </div>
    </div>		
</body>
</html>
